/**
 *
 * queue.h - Copy Queue Library
 *
 * The MIT License
 *
 * Copyright (c) 2008 John Van Enk
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

#ifndef __CPQ_QUEUE_H__
#define __CPQ_QUEUE_H__ __CPQ_QUEUE_H__

#include <action.h>
#include <cpq_error.h>
#include <session.h>

struct _CPQ_Queue_s;
struct _CPQ_Queue_Element_s;

typedef struct _CPQ_Queue_s         CPQ_Queue_s_t;
typedef struct _CPQ_Queue_Element_s CPQ_Queue_Element_s_t;

/**
 * Queue
 */
struct _CPQ_Queue_s
{
    struct _CPQ_Queue_Element_s * first;
    struct _CPQ_Queue_Element_s * last;
    unsigned int           count;
};

/**
 * Queue Element
 */
struct _CPQ_Queue_Element_s
{
    struct _CPQ_Queue_Element_s * next;
    struct _CPQ_Action_s        * value;
};

/**
 * Initialize a new queue.
 */
CPQ_Error_e_t CPQ_Queue_Init(CPQ_Queue_s_t * queue);

/**
 * Enqueue a new element.
 */
CPQ_Error_e_t CPQ_Queue_Enqueue(CPQ_Queue_s_t * queue, CPQ_Queue_Element_s_t * element);

/**
 * Dequeue the front element. Returns a pointer to the deqeueued element.
 */
CPQ_Queue_Element_s_t * CPQ_Queue_Dequeue(CPQ_Queue_s_t * queue);

/**
 * Returns a pointer to the front element without removing it from the queue.
 */
CPQ_Queue_Element_s_t * CPQ_Queue_Peek(CPQ_Queue_s_t * queue);

/**
 * Removes all elements from the queue.
 */
CPQ_Error_e_t CPQ_Queue_Clear(CPQ_Queue_s_t * queue);

#endif /* __CPQ_QUEUE_H__ */

